package com.tiantianbook.mvpretrofitrxjavademo.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import butterknife.ButterKnife;
import butterknife.Unbinder;


/**
 * name:BaseActivity
 * author:moo.
 * date:2016/8/31.
 * instruction:
 */
public abstract class BaseActivity<V, T extends BasePresenter<V>> extends AppCompatActivity {
    protected T mPresenter;
    private Unbinder bind;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        bind = ButterKnife.bind(this);
        mPresenter = initPresenter();
        initView();
    }


    @Override
    protected void onResume() {
        super.onResume();
        mPresenter.attach((V) this);
        initData();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.dettach();
        bind.unbind();
    }

    protected abstract T initPresenter();

    protected abstract int getLayoutId();

    protected abstract void initData();

    protected abstract void initView();

}
